#-*- coding:utf8-*-
from bs4 import BeautifulSoup
import lxml
from lxml import etree
import os 

chapter = os.listdir('D:/Python/Project/novel')
def analyse_text(html):
	path = os.path.join('D:/Python/Project/novel', html)
	with open(path) as f:
		novel = f.read()
	soup = BeautifulSoup(novel, 'lxml')
	matter = soup.find_all('dd')
	for dd in matter:
		title = matter[0].text
		path = 'D:/Python/Project/content/' + title
		try:
			if dd.get('id') == 'contents':
				text = str(dd.text)
				text = text.strip('  ')
				file = open(path, 'w', encoding='utf-8',errors='ignore')
				file.write(text)
				file.close()
		except OSError as e:
			print('There is something wrong')
for html in chapter:
	analyse(html)
	print(chapter.index(html))